package com.woniu.service.impl;

import com.woniu.entity.PersonUser;
import com.woniu.dao.PersonUserDao;
import com.woniu.service.PersonUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PersonUser)表服务实现类
 *
 * @author makejava
 * @since 2020-03-24 19:04:30
 */
@Service("personUserService")
public class PersonUserServiceImpl implements PersonUserService {
    @Resource
    private PersonUserDao personUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PersonUser queryById(Integer id) {
        return this.personUserDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<PersonUser> queryAllByLimit(int offset, int limit) {
        return this.personUserDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param personUser 实例对象
     * @return 实例对象
     */
    @Override
    public PersonUser insert(PersonUser personUser) {
        this.personUserDao.insert(personUser);
        return personUser;
    }

    /**
     * 修改数据
     *
     * @param personUser 实例对象
     * @return 实例对象
     */
    @Override
    public PersonUser update(PersonUser personUser) {
        this.personUserDao.update(personUser);
        return this.queryById(personUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.personUserDao.deleteById(id) > 0;
    }

    @Override
    public Integer findPlotIdByUserId(Integer userId) {
        return personUserDao.findPlotIdByUserId(userId);
    }

    @Override
    public PersonUser findIdByName(String name) {
        return personUserDao.findIdByName(name);
    }

    @Override
    public String findNickNameByName(String name) {
        return personUserDao.findNickNameByName(name);
    }

    @Override
    public List<PersonUser> findPersonByPoltId(Integer plotId) {
        return personUserDao.findPersonByPoltId(plotId);
    }
}